<template>
	<navbar title="支付结果" :isBack="true"></navbar>
	<view class="" v-if="state"
		style="padding: 100rpx 50rpx 0 50rpx;display: flex;justify-content: center;align-items: center;flex-direction: column;">
		<image src="../../static/image/success.png" style="width: 136rpx;height: 120rpx;" mode=""></image>

		<view class="" style="margin-top: 76rpx;font-weight: bold;font-size: 40rpx;">
			<span>支付成功</span>

		</view>
		<view class="" style="margin-top: 20rpx;font-size: 28rpx;color: #5A5A5A;">
			<span>恭喜您，成功购买！</span>

		</view>
		<view class="" style="margin-top: 138rpx;display: flex;justify-content: space-between;width: 100%;">
			<view class="" @tap="home"
				style="width: 296rpx;height: 84rpx;border: 1rpx solid #9A9A9A;border-radius: 114rpx;display: flex;justify-content: center;align-items: center;color: #5A5A5A;">
				返回首页
			</view>
			<view class="" @tap="orderList"
				style="width: 296rpx;height: 84rpx;border: 1rpx solid #405EEC;border-radius: 114rpx;display: flex;justify-content: center;align-items: center;color: #405EEC;">
				查看订单
			</view>
		</view>

	</view>
	<view class="" v-if="state == 0"
		style="padding: 100rpx 50rpx 0 50rpx;display: flex;justify-content: center;align-items: center;flex-direction: column;">

		<image src="../../static/image/error.png" style="width: 136rpx;height: 120rpx;" mode=""></image>
		<view class="" style="margin-top: 76rpx;font-weight: bold;font-size: 40rpx;">

			<span>支付失败</span>
		</view>
		<view class="" style="margin-top: 20rpx;font-size: 28rpx;color: #5A5A5A;">

			<span>请重新支付</span>
		</view>

		<view style="margin-top: 138rpx;display: flex;justify-content: center;width: 100%;">

			<view class="" @tap="pays"
				style="width: 296rpx;height: 84rpx;border: 1rpx solid #405EEC;border-radius: 114rpx;display: flex;justify-content: center;align-items: center;color: #405EEC;">
				重新支付
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { onLoad, onShareAppMessage, onShareTimeline, onReachBottom } from '@dcloudio/uni-app'
	import { reactive, ref } from 'vue'
	import { cashier, orderPay } from '@/service/api/index'
	import tools from '@/utils/tools'
	const state = ref(0)
	const id = ref()
	onLoad((opt) => {
		state.value = opt.state;
		id.value = opt.id;
	})
	//重新支付
	const pays = async () => {
		const res = await orderPay({ id: id.value });

		tools.requestPayment(res.msg).then((res) => {
			tools.showToast('支付成功')
			setTimeout(() => {
				tools.navTo('/pagesA/pay/payResult?state=1&id=' + id.value, 4)
			}, 1000)

		}).catch((err) => {
			tools.showToast('取消支付')
			setTimeout(() => {
				tools.navTo('/pagesA/pay/payResult?state=0&id=' + id.value, 4)
			}, 1000)
		})

	}
	const home = () => {
		console.log(123);
		tools.navTo('/pages/home/index', 3)
	}
	const orderList = () => {
		tools.navTo('/pagesA/order/myOrder',4)
	}
</script>

<style scoped lang="scss">
</style>